package arsmodeller.editpolicies;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.DirectEditPolicy;
import org.eclipse.gef.requests.DirectEditRequest;

import arsmodeller.commands.ThingRenameCommand;
import arsmodeller.figure.ThingFigure;
import arsmodeller.model.Thing;

public class ThingDirectEditPolicy extends DirectEditPolicy {
	@Override
	protected Command getDirectEditCommand(DirectEditRequest request) {
		ThingRenameCommand command = new ThingRenameCommand();
		command.setModel((Thing) getHost().getModel());
		command.setNewName((String) request.getCellEditor().getValue());
		return command;
	}

	@Override
	protected void showCurrentEditValue(DirectEditRequest request) {
		String value = (String) request.getCellEditor().getValue();
		((ThingFigure) getHostFigure()).getNameLabel().setText(value);
	}
}
